package com.xsomnus.mc.kafka.producer.controller;

import com.xsomnus.mc.kafka.producer.config.KafkaSendResultHandler;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.support.converter.KafkaMessageHeaders;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author @xsomnus666_xiawenye★
 * @since 2019/4/26 0026 17:39
 * 当你发现自己的才华撑不起野心时，就请安静下来学习吧
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/producer")
public class KafkaProducerController {

    private final KafkaTemplate kafkaTemplate;

    private final KafkaSendResultHandler kafkaSendResultHandler;


    @PostMapping("/send")
    public String send(@RequestParam String topic, @RequestParam String msg) {
        ListenableFuture send = kafkaTemplate.send(new Message<Object>() {
            @Override
            public Object getPayload() {
                return "hello";
            }

            @Override
            public MessageHeaders getHeaders() {
                return null;
            }
        });
        return null;
    }

}
